home *** CD-ROM | disk | FTP | other *** search
- #ifndef MSC
-
- /* Non-MSC Version */
-
-
- /* NOTE: This procedure should only be used for
- large data model programs (i.e., Compact, Large, Huge) */
-
- #if (defined(M_I86CM) || defined(M_I86LM) || defined(M_I86HM))
-
- #include <stdio.h>
- #include "alloc.h"
-
- extern ATABLE AllocationTable [] ; /* Provide storage for block pointers */
- extern SUNIT MBSize ; /* Default allocation block size */
- extern SUNIT NEntry ; /* Number of table entries */
- extern size_t _asizds ;
- extern size_t _abrktb [] ;
- extern size_t _psp ;
-
- DumpHeap ( msg )
-
- char msg [] ; /* Message to be displayed at beginning of dump */
-
- /*
- +----------------------------------------------------+
- | |
- | This procedure is called to dump to a file |
- | called 'memory.dmp' the current memory block |
- | sizes. (Replacement Version) |
- | |
- +----------------------------------------------------+
- */
-
- {
- FILE *file ;
- FILE *fopen () ;
- HEADER *Header ;
- long codesize, dataused, dataalloced, allocused, allocated ;
- long totalf, totalu ;
- SUNIT offset, *bptr, bsize;
- int i ;
- int totalinuse ;
- int totalfree ;
- char string [ 83] ;
- char buffer [BUFSIZ] ;
-
- if ((file = fopen ( "memory.new", "a" )) == NULL )
- return ;
- setbuf ( file, buffer ) ;
-
- fprintf ( file, "\n\n **** Heap Dump **** \n" ) ;
- fprintf ( file, "Message: %s\n", msg ) ;
- ProgSize (&codesize, &dataused, &dataalloced, &allocused, &allocated) ;
- fprintf ( file,
- "C: %6ld DU: %6ld DA: %6ld AU: %6ld AA: %6ld Total: %6ld\n",
- codesize, dataused, dataalloced, allocused, allocated,
- codesize + dataalloced + allocated ) ;
-
- totalf = totalu = 0L ;
- totalinuse = totalfree = 0 ;
- for ( i = 0 ; i < NEntry ; i++ ) {
- Header = AllocationTable [i].Header ;
- fprintf ( file,
- "\nBlock Pointer: %p, Block Size: %u, Collapsed: %d, LFBlock: %u\n",
- Header, AllocationTable [i].Size, Header->Collapsed, Header->LFBlock ) ;
-
- offset = HSIZE ;
- while ( offset < Header->BytesUsed ) {
- bptr = (SUNIT *) Header + offset/SSIZE ;
- bsize = *bptr & ~FREE ;
- fprintf ( file, "Heap Pointer - %p, Size %5u", bptr+1, bsize ) ;
- if ( (*bptr & FREE) ) {
- fprintf ( file, ", FREE\n" ) ;
- totalf += (long) bsize ;
- totalfree++ ;
- }
- else {
- fprintf ( file, ", **IN USE**\n" ) ;
- totalu += (long) bsize ;
- totalinuse++ ;
- } ;
- offset += bsize+SSIZE ;
- } ;
- if ( offset != Header->BytesUsed )
- fprintf ( file, "*** Size Error, Header->BytesUsed - %u, offset - %u\n",
- Header->BytesUsed, offset ) ;
- } ;
- fprintf ( file, "\nTotal space in Use - %7ld" , totalu ) ;
- fprintf ( file, "\nTotal space free - %7ld" , totalf ) ;
- fprintf ( file, "\nTotal number in Use - %7d" , totalinuse ) ;
- fprintf ( file, "\nTotal number free - %7d\n" , totalfree ) ;
- fclose ( file ) ;
- }
- #endif
-
- #else
-
- /* MSC Version */
-
- #include <stdio.h>
- #include <dos.h>
- #include <malloc.h>
-
- DumpHeap (msg)
-
- char msg [] ;
-
- /*
- +----------------------------------------------------+
- | |
- | This procedure is called to dump to a file |
- | called 'memory.dmp' the current memory block |
- | sizes. (MSC Version) |
- | |
- +----------------------------------------------------+
- */
-
- {
- FILE *file ;
- FILE *fopen () ;
- _HEAPINFO hinfo ;
- long codesize, dataused, dataalloced, allocused, allocated ;
- long totalf, totalu ;
- char string [ 83] ;
- char buffer [BUFSIZ] ;
- int totalinuse ;
- int totalfree ;
- size_t lastseg ;
-
-
- if ((file = fopen ( "memory.msc", "a" )) == NULL )
- return ;
- setbuf ( file, buffer ) ;
-
- fprintf ( file, "\n\n **** Heap Dump **** \n" ) ;
- fprintf ( file, "Message: %s\n", msg ) ;
- ProgSize (&codesize, &dataused, &dataalloced, &allocused, &allocated) ;
- fprintf ( file,
- "C: %6ld DU: %6ld DA: %6ld AU: %6ld AA: %6ld Total: %6ld\n",
- codesize, dataused, dataalloced, allocused, allocated,
- codesize + dataalloced + allocated ) ;
-
- hinfo._pentry = NULL ;
- totalf = totalu = 0L ;
- lastseg= 0 ;
- totalinuse = totalfree = 0 ;
- while ( _heapwalk ( &hinfo ) == _HEAPOK ) {
- if ( lastseg != FP_SEG (hinfo._pentry) )
- fprintf ( file, "\n" ) ;
- lastseg = FP_SEG (hinfo._pentry) ;
- fprintf ( file, "Heap Pointer - %p, Size %5u", hinfo._pentry,
- hinfo._size ) ;
- if ( hinfo._useflag == _USEDENTRY ) {
- fprintf ( file, ", **IN USE**\n" ) ;
- totalu += (long) hinfo._size ;
- totalinuse++ ;
- }
- else {
- fprintf ( file, ", FREE\n" ) ;
- totalf += (long) hinfo._size ;
- totalfree++ ;
- } ;
- } ;
- fprintf ( file, "\nTotal in Use - %7ld" , totalu ) ;
- fprintf ( file, "\nTotal free - %7ld" , totalf ) ;
- fprintf ( file, "\nTotal number in Use - %7d" , totalinuse ) ;
- fprintf ( file, "\nTotal number free - %7d\n" , totalfree ) ;
- fclose ( file ) ;
- }
- #endif
-